#ifndef HTTPSERVER_H_INCLUDED
#define HTTPSERVER_H_INCLUDED


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <assert.h>
#include <sys/queue.h>
#include <event.h>


#include <pthread.h>

#include <event2/keyvalq_struct.h>
#include <event2/http.h>
#include <event2/event.h>
#include <event2/buffer.h>
#include "event2/http_struct.h"
#include "event2/dns.h"
#include "event2/thread.h"



#include "../proc/proc_info.h"
#include "../cpu/cpu_info.h"
#include "../disk/disk_info.h"
#include "../cjson/cJSON.h"

#include "../utils/utils.h"





//未知的地质请求处理函数
void http_request_cb(struct evhttp_request *req, void *arg);
//打印网络请求信息
void print_request(struct evhttp_request *req, void *arg);
//网络执行命令请求
void order_request_cb(struct evhttp_request *req, void *arg);

//获取硬盘信息
void disk_request_cb(struct evhttp_request *req, void *arg);

void mem_request_cb(struct evhttp_request *req, void *arg);

char* get_mem_json_str();


void cpus_request_cb(struct evhttp_request *req, void *arg);
void process_request_cb(struct evhttp_request *req, void *arg);
void start_time_request_cb(struct evhttp_request *req, void *arg);
void cores_request_cb(struct evhttp_request *req, void *arg);
void net_request_cb(struct evhttp_request *req, void *arg);

//http返回函数
void response_msg(struct evhttp_request *req, const char *msg,int code);

//比较TOKEN是否一致
int token_compare(struct evhttp_request *req);

//httpserver开始运行
void run_http_server(int port);

void submit_sys_info(char* ip,int port);

//alram处理函数
void sig_exc_alarm(int sig);

//命令实际执行函数
void* execute_command(void* arg);

//执行网络请求命令，并返回请求结果
void order_response(struct evhttp_request *req,const char* command);

//获取请求数据
char* get_request_input(struct evhttp_request *req);

void remote_read_callback(struct evhttp_request* remote_rsp, void* arg);
int read_header_done_callback(struct evhttp_request* remote_rsp, void* arg);
void read_chunk_callback(struct evhttp_request* remote_rsp, void* arg);
void remote_request_error_callback(enum evhttp_request_error error, void* arg);
void remote_connection_close_callback(struct evhttp_connection* connection, void* arg);

int send_sys_info(const char*);

#endif // HTTPSERVER_H_INCLUDED
